package com.sky.mapper;

import com.sky.dto.GoodsSalesDTO;
import com.sky.entity.Orders;
import com.sky.entity.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDate;
import java.util.List;

@Mapper
public interface ReportMapper {
    /**
     * 查询begin到end的orders
     * @param begin
     * @param end
     * @return
     */
    @Select("select * from orders where checkout_time >= #{begin} and checkout_time <= #{end}")
    List<Orders> turnoverStatistics(LocalDate begin, LocalDate end);

    /**
     * 查询now的新增用户
     * @param now
     * @return
     */
    @Select("select count(*) from user where DATE (create_time) = #{now} ")
    Integer newUserStatistics(LocalDate now);

    /**
     * 查询到now的总用户
     * @param now
     * @return
     */
    @Select("select count(*) from user where create_time < #{now}")
    Integer totalUserStatistics(LocalDate now);

    /**
     * 查询begin 到 end范围内的订单
     * @param begin
     * @param end
     * @return
     */
    @Select("select * from orders where DATE(order_time) >= #{begin} and DATE(order_time) <= #{end} ")
    List<Orders> ordersStatistics(LocalDate begin, LocalDate end);

    /**
     * 查询begin到end范围内的用户
     * @param begin
     * @param end
     * @return
     */
    @Select("select * from user where DATE (create_time) >= #{begin} and DATE (create_time) <= #{end}")
    List<User> userStatistics(LocalDate begin, LocalDate end);

    /**
     * 查询begin到end范围内的菜品销量
     * @param begin
     * @param end
     * @return
     */
    @Select("select od.name,od.number from order_detail od join orders o on od.order_id = o.id " +
            "where DATE(o.order_time) >= #{begin} and DATE (o.order_time) <=#{end}")
    List<GoodsSalesDTO> salesTop10(LocalDate begin, LocalDate end);
}
